package com.quotes.simulation;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.quotes.datamodell.BuySell;

public class MarketOrderList 
{
	private List<MarketOrder> list = new ArrayList<MarketOrder>();
	
	public MarketOrderList() {
	}
	
	public MarketOrderList(List<MarketOrder> list) {
		list.addAll(list);
	}
	
	public void add(MarketOrder obj) {
		list.add(obj);
	}
	
	public void add(MarketOrderList list) {
		this.list.addAll(list.getMarketOrders());
	}
	
	public List<MarketOrder> getMarketOrders() {
		return list;
	}
	
	public MarketOrderList byDirection(BuySell buySell) {
		MarketOrderList result = new MarketOrderList();
		
		for (MarketOrder order : list) {
			if (order.getBuySell() == buySell) {
				result.add(order);
			}
		}
		
		return result;
	}
	
	public MarketOrderList byYahooName(String yahooName) {
		MarketOrderList result = new MarketOrderList();
		
		for (MarketOrder order : list) {
			if (order.getSymbol().getYahooName() == yahooName) {
				result.add(order);
			}
		}
		
		return result;
	}
	
	public MarketOrderList byDate(Date date) {
		MarketOrderList result = new MarketOrderList();
		
		for (MarketOrder order : list) {
			if (order.getDate().compareTo(date) == 0) {
				result.add(order);
			}
		}
		
		return result;
	}
	
	public MarketOrder highestAdx() {
		if (list.size() == 0)
			return null;
		
		double currentAdx = 0;
		MarketOrder currentOrder = null;
		
		for (MarketOrder order : list) {
			if (order.getInfo("adx") > currentAdx)
				currentOrder = order;
		}
		
		return currentOrder;
	}
}
